/*
* JavaScript File - used by registration.jsp.
* Validate the form input box
*/		

function hide(){
	   document.getElementById("adminCode").style.visibility="hidden";
	}
		
function show(){
		document.getElementById("adminCode").style.visibility="visible";
}

function usernameValidation(username){
		
		if (username == null || username.value == ""){
		    alert("Please enter a username");
			return false;
		}
		
		if (username.value.length > 8){
			alert("The username can contain up to 8 characters");
			return false;
		}
		return true;
	}
		
function passwordValidation(password){
		
		if (password == null || password.value == ""){
		    alert("Please enter a password");
			return false;
		}
		  	
		if (password.value.length > 8) {
			alert("The password can contain up to 8 characters");
			return false;
		}
		return true;
	}
	
function passwordValidation2(password , password2){

		if (password2 == null || password2.value == "" ){
		    alert("Please re-enter your password");
			return false;
		}
		
		if (password.value != password2.value) {
			alert("Please enter the same password");
			return false;
		}
		return true;
	}
		
function firstNameValidation(firstName){
			
		if (firstName == null || firstName.value==""){
			alert("Please enter your first name");
			return false;
		}
		  	
		if (firstName.value.length > 15) {
			alert("The first name attribute can contain up to 15 characters");
			return false;
		}
		return true;
	}
		
function lastNameValidation(lastName){
		
		if (lastName == null || lastName.value==""){
			alert("Please enter your last name");
			return false;
		}
		
		if (lastName.value.length>15) {
			  	alert("The last name attribute can contain up to 15 characters");
				return false;
		}
		return true;
	}

function phoneValidation(number){
			
		if (number == null || number.value == ""){
			alert("Please enter your phone number");
			return false;
		}
		
		if (number.value.length>15) {
			  	alert("The phone attribute can contain up to 15 characters");
				return false;
		}
		
		for(var i=0 ; i < number.value.length; ++i){
            
			var new_key = number.value[i]; 
            if((new_key < "0") || (new_key > "9")){
                 alert("The phone number can contain only numbers");
				 return false;
            }
         }
		 
		return true;
	}
		

function formValidation(form){

		return (usernameValidation(form.username) &&
			   passwordValidation(form.password) &&
			   passwordValidation2(form.password , form.password2) &&
			   firstNameValidation(form.firstName) &&
			   lastNameValidation(form.lastName) &&
			   phoneValidation(form.number));
	}